package ar.edu.itba.twiteros.bean;

import java.util.Date;
import java.util.StringTokenizer;

import org.json.simple.JSONObject;

public class TwitterosBean {

	public String diference(Date date){
		String dif;
		Date now= new Date();
		long miliNow= now.getTime();
		long miliDate= date.getTime();
		long diference= miliNow-miliDate;
		
		int s= (int)diference/1000;
		int m= (int)s/60;
		int h= (int)m/60;
		int d= (int)h/24;
		
		if(d>0){
			dif= d + " days Ago";
		}else if(h>0){
			dif= h + " hours Ago";
		}else if(m>0){
			dif= m + " minute Ago";
		}else if(s>0){
			dif= s + " seconds Ago";
		}else{
			dif= "0 seconds Ago";
		}
		
		return dif;		
	}

	
	public String parseUrl(String msg){
		String ans="";
		String token;
		StringTokenizer tokens= new StringTokenizer(msg, " ");
		
		while(tokens.hasMoreTokens()){			
			//http://
			token= tokens.nextToken();
			if(token.length()>7 && token.toLowerCase().contains("http://")){
				ans+= "<a href='"+ token + "'>" + token + "</a> ";
			}else{
				ans+= token + " ";
			}
		}
		
		return ans;
	}
	

}
